<template>
  <div>
    <!-- <div class="search">
      <div class="search-input">
        <icon class="search-icon" type="search" size="20"></icon>搜索
      </div>
    </div> -->
    <search></search>
    <!-- 轮播图 -->
    <swiper indicator-dots autoplay circular>
      <block v-for="(item ,index) in imgUrl" :key="index">
        <swiper-item>
          <image :src="item.image_src" class="slide-image" mode="widthFix"></image>
        </swiper-item>
      </block>
    </swiper>
    <!-- 首页分类 -->
    <div class="menu">
      <div class="menu-item" v-for="(item,index) in menu" :key="index">
        <image class="menu-image" :src="item.image_src"></image>
      </div>
    </div>
    <!-- 楼层部分 -->
    <div class="floor">
      <div class="floor-item" v-for="(item,index) in floors" :key="index">
       <div class="floor-head">
         <image :src="item.floor_title.image_src"  mode="aspectFit"></image>
       </div>
       <div class="floor-body">
         <div class="floor-body-left">
           <image :src="item.product_list[0].image_src"></image>
         </div>
         <div class="floor-body-right">
           <image 
           v-for="(subItem,subIndex) in item.product_list"
            :key="subIndex" 
            :src="subItem.image_src"
            v-show="subIndex !=0"
            >
           </image>
         </div>
       </div>
      </div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request"
import search from "@/components/search"
export default {
  data () {
    return {
      // 轮播图图片地址数组
      imgUrl: [],
      // 分类图片地址数组
      menu:[],
      // 楼层图片地址数组
      floors:[]
    }
  },
  components: {
    search
  },
  mounted () {
    // // 先把this存储起来
    // let that = this;
    // // 调用小程序的请求api
    // wx.request({
    //   url: "https://www.zhengzhicheng.cn/api/public/v1/home/swiperdata", 
    //   success(res) {
    //     that.imgUrl=res.data.message
    //   } 
    // })
    // wx.request({
    //   url: "https://www.zhengzhicheng.cn/api/public/v1/home/catitems",
    //   success(res){
    //     // console.log(res)
    //     that.menu=res.data.message
    //   }
    // })
    request("https://www.zhengzhicheng.cn/api/public/v1/home/swiperdata").then(res=>{
      this.imgUrl = res.data.message
    });

    request("https://www.zhengzhicheng.cn/api/public/v1/home/catitems").then(res=>{
      this.menu = res.data.message
      
    });
    request("https://www.zhengzhicheng.cn/api/public/v1/home/floordata").then(res=>{
      this.floors=res.data.message
    })
  }
}
</script>

<style lang="scss">

.slide-image{
  width: 100%;

}
.menu{
  display: flex;
  justify-content: space-around;
  padding: 24rpx 0;
}
.menu-image{
  width: 128rpx;
  height: 140rpx;
}
.floor{
  &-head{
    background-color: #f4f4f4;
    image{
      width: 100%;
      height: 88rpx;
    }  
  }
  &-body{
    display: flex;
    padding: 20rpx 0 20rpx 16rpx;

    &-left{  
      margin-right: 10rpx;
      image{
        width: 232rpx;
        height: 386rpx;
      }
    }
    &-right{
      display: flex;
      flex-wrap: wrap;
      image{
        height: 188rpx;
        width: 233rpx;
        margin-right: 10rpx;
      }
    }
  }
}
</style>
